// $codepro.audit.disable com.instantiations.assist.eclipse.analysis.audit.rule.effectivejava.alwaysOverridetoString.alwaysOverrideToString, spellCheckComments, spellCheckIdentifiers, spellCheckStringLiterals
/**
 * Package db
 */
package teamrocket.db; // $codepro.audit.disable packagePrefixNamingConvention

import java.sql.SQLException;
import java.util.Date;


/**
 * Represents a login attempt for a certain user
 * @author Stephen
 *
 * @version $Revision: 1.0 $
 */
public class LoginAttempt {
	
	/**
	 * Field userid.
	 */
	private final int userid;

	/**
	 * Field success.
	 */
	private final boolean success;
	
	/**
	 * Field date.
	 */
	private final Date date;

	/**
	 * Creates a login attempt object in memory
	 * @param userid
	 * @param success
	 * @param date
	 */
	public LoginAttempt(int userid, boolean success, Date date){
		this.userid = userid;
		this.success = success;
		this.date = date;
	}

	/**
	 * Method getUserID.
	 * @return int
	 */
	public int getUserID(){
		return userid;
	}
	
	/**
	 * Method getSuccess.
	 * @return boolean
	 */
	public boolean getSuccess(){ // $codepro.audit.disable booleanMethodNamingConvention
		return success;
	}
	
	/**
	 * Method getDate.
	 * @return Date
	 */
	public Date getDate(){
		return date;
	}
	
	/**
	 * Creates a login attempt in the database
	 */
	public void create(){
		try {
			DBWrapper.execute("INSERT INTO loginattempt " +
					"(userid, success, date) VALUES(?,?,?)", 
					this.userid,
					this.success?1:0,
					this.date.getTime());
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
